/*
acturally i don't like using too much functions
use a library is much better
*/
#include<stdio.h>
int array[10];
void getarray(int n){
    printf("array:");
    for(int i=0;i<n;i++)
    scanf("%d",&array[i]);
    return;
}
void putarray(int n){
    printf("array:");
    for(int i=0;i<n;i++)
    printf("%3d",array[i]);
    printf("\n");
    return;
}
double avg(int n){
    int i;
    double ans=0;
    for(i=0;i<n;i++)
    ans+=array[i];
    ans=ans/n;
    return ans;
}
void searcharray(int x,int n){//check the array
    int i;
    for(i=0;i<n;i++)
    {
        if(array[i]==x)
        {
            printf("num exisit! position:%d\n",i);
            return;//if exist jump out the function
        }
    }
    printf("does not exisit\n");
    return;
}
void sortarray(int n)//sort the array
{
    int dat,i,i1;
    for(i=0;i<n;i++)
    for(i1=i+1;i1<n;i1++)
    if(array[i1]<array[i])
    {
        dat=array[i];
        array[i]=array[i1];
        array[i1]=dat;
    }
}
int main(){
    int tgt,n;
    while(1)
    {
        printf("Enter a number between1~10:");
        scanf("%d",&n);
        if(n<1||n>10)printf("error,please reenter\n");
        else break;
    }
    getarray(n);
    putarray(n);
    printf("avg:%f\n",avg(n));
    printf("putin tgt:");
    scanf("%d",&tgt);
    searcharray(tgt,n);
    sortarray(n);
    putarray(n);
    return 0;
}